package com.ktjy.controller;

import com.ktjy.ch06.service.ISysUserService;
import com.ktjy.ch06.entity.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

/**
 * @author lqm
 * @ClassName IndexController
 * @description: TODO
 */
@Controller
public class IndexController {

    @Autowired
    ISysUserService sysUserService;

    @RequestMapping("/")
    public String helloWord(Model model, HttpSession session) {
        model.addAttribute("msg", "hello word!");
        session.setAttribute("sessionMsg", "hello word!!!!!");
        return "layout/userList";
    }


    @RequestMapping("/doLogin")
    public String doLogin(String usrName, String usrPassword, Model model, HttpSession session) {

        SysUser user = sysUserService.loginPlus(usrName, usrPassword);
        if (user != null) {
            session.setAttribute("loginUser", user);
            return "redirect:/ch06/sysUser/list";
//          return new ModelAndView(new RedirectView("/ch06/sysUser/list"));
        } else {
            model.addAttribute("errorMsg", "账号或密码错误！");
            return "login";
//          return new ModelAndView("/ch06/sysUser/list");
        }

    }


}
